sync up enum strings
authorØyvind Kolås <ok@src.gnome.org>
Tue, 23 Aug 2005 07:45:05 +0000 (07:45 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Tue, 23 Aug 2005 07:45:05 +0000 (07:45 +0000)
ChangeLog
babl/babl-classes.c
babl/babl-db.h
babl/babl-internal.c
babl/babl-memory.c
babl/babl-memory.h

index 01a6933118b51eaeca3adff0fae71a170ba2e04c..18743efeaa2fbd1e5557ffc10a8370c9f7c2444e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-08-23  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-memory.[ch]: added additonal sanity checking (only
+       handling babl-memory allocated memory in free and realloc.) And added
+       new function babl_dup (void*), which duplicates an allocation.
+       * babl/babl-db.h: have an initial database size.
+
 2005-08-23  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-classes.c: Update class names to be in sync with enum in
index 0d2e0285c7c0505e08491da4c93bcdcf7c4da558..5b278bf46c935e4217fa25b24566eebe654a9983 100644 (file)
@@ -23,6 +23,8 @@ static const char *class_names[] =
   {
     "BablInstance",
     "BablType",
+    "BablTypeInteger",
+    "BablTypeFloat",
     "BablSampling",
     "BablComponent",
     "BablModel",
@@ -31,12 +33,12 @@ static const char *class_names[] =
     "BablConversionType",
     "BablConversionTypePlanar",
     "BablConversionModelPlanar",
-    "BablConversionPixelFormatPlanar",
+    "BablConversionPixelFormat",
     "BablConversionPixelFormatPlanar",
     "BablFish",
-    "BablReferenceFish",
+    "BablFishReference",
     "BablImage",
-    "BablCeiling"
+    "BablSky"
   };
 
 const char *
index 8b20181befc97030bcc89436d6bb777fc2a48051..f0b4abe54862523b6a085232f9cead24c8651cd3 100644 (file)
 #include <string.h>
 
 #define DB_DEF             static inline
-#define DB_INITIAL_SIZE    0
+
+#ifndef DB_INITIAL_SIZE
+#define DB_INITIAL_SIZE    16 
+#endif
+#ifndef DB_INCREMENT_SIZE
 #define DB_INCREMENT_SIZE  16
+#endif
 
 
 /* file scope variables, for this .c file's database */
@@ -70,8 +75,11 @@ db_init(void)
   if (0==db_size)
     {
       db_size = DB_INITIAL_SIZE;
-      db = babl_malloc (db_size * sizeof (BablInstance*));
-      memset (db, 0, db_size * sizeof (BablInstance*));
+      db = NULL;
+      if (db_size)
+        {
+          db = babl_calloc (sizeof (BablInstance*), db_size);
+        }
     }
 }
 
index 0d2e0285c7c0505e08491da4c93bcdcf7c4da558..5b278bf46c935e4217fa25b24566eebe654a9983 100644 (file)
@@ -23,6 +23,8 @@ static const char *class_names[] =
   {
     "BablInstance",
     "BablType",
+    "BablTypeInteger",
+    "BablTypeFloat",
     "BablSampling",
     "BablComponent",
     "BablModel",
@@ -31,12 +33,12 @@ static const char *class_names[] =
     "BablConversionType",
     "BablConversionTypePlanar",
     "BablConversionModelPlanar",
-    "BablConversionPixelFormatPlanar",
+    "BablConversionPixelFormat",
     "BablConversionPixelFormatPlanar",
     "BablFish",
-    "BablReferenceFish",
+    "BablFishReference",
     "BablImage",
-    "BablCeiling"
+    "BablSky"
   };
 
 const char *
index e7eb140ee0910b158c7758dd2ad94e6f9c564c98..3a7c81bbc466c06194c8c53d2d29e27b98c12c43 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "babl-internal.h"
 
-static int mallocs=0;
-static int frees=0;
-static int strdups=0;
-static int reallocs=0;
-static int callocs=0;
+static char *signature = "So long and thanks for all the fish.";
+
+typedef struct
+{
+  char   *signature;
+  size_t  size;
+} BablAllocInfo;
+
+#define OFFSET   (sizeof(BablAllocInfo))
+
+#define BAI(ptr)    ((BablAllocInfo*)(((void*)ptr)-OFFSET))
+#define IS_BAI(ptr) (BAI(ptr)->signature == signature)
+
+static int mallocs  = 0;
+static int frees    = 0;
+static int strdups  = 0;
+static int reallocs = 0;
+static int callocs  = 0;
+static int dups     = 0;
 
 static const char *
 mem_stats (void)
 {
   static char buf[128];
-  sprintf (buf, "mallocs:%i callocs:%i strdups:%i allocs:%i frees:%i reallocs:%i\t|",
-    mallocs, callocs, strdups, mallocs+callocs+strdups, frees, reallocs);
+  sprintf (buf, "mallocs:%i callocs:%i strdups:%i dups:%i allocs:%i frees:%i reallocs:%i\t|",
+    mallocs, callocs, strdups, dups, mallocs+callocs+strdups+dups, frees, reallocs);
   return buf;
 }
 
@@ -41,32 +56,55 @@ void *
 babl_malloc (size_t size)
 {
   void *ret;
-  ret = malloc (size);
+
+  assert (size); 
+  ret = malloc (size + OFFSET);
   if (!ret)
     babl_log ("%s(%i): failed", __FUNCTION__, size);
+
+  BAI(ret + OFFSET)->signature = signature;
+  BAI(ret + OFFSET)->size      = size;
   mallocs++;
-  return ret;
+  return ret + OFFSET;
 }
 
 char *
 babl_strdup (const char *s)
 {
   char *ret;
-  ret = strdup (s);
+
+  ret = babl_malloc (strlen (s)+1);
   if (!ret)
     babl_log ("%s(%s): failed", __FUNCTION__, s);
+  strcpy (ret, s); 
+
   strdups++;
+  mallocs--;
   return ret;
 }
 
+void *
+babl_dup (void *ptr)
+{
+  void *ret;
+  assert (IS_BAI (ptr));
+
+  ret = babl_malloc (BAI(ptr)->size);
+  memcpy (ret, ptr, BAI(ptr)->size);
+
+  dups++;
+  mallocs--;
+  return NULL;
+}
+
 void
 babl_free (void *ptr)
 {
   if (!ptr)
     return;
-  free (ptr);
+  assert(IS_BAI(ptr));
+  free (BAI(ptr));
   frees++;
 }
 
@@ -75,30 +113,38 @@ babl_realloc (void   *ptr,
               size_t  size)
 {
   void *ret;
-  ret = realloc (ptr, size);
+
+  if (!ptr)
+    {
+      return babl_malloc (size);
+    }
+
+  assert (IS_BAI (ptr));
+  ret = realloc (BAI(ptr), size + OFFSET);
 
   if (!ret)
     babl_log ("%s(%p, %i): failed", __FUNCTION__, ptr, size);
   
-  reallocs++;
-
-  if (!ptr)     /* to make the statistics work out */
-    mallocs++;
+  BAI(ret+OFFSET)->signature = signature;
+  BAI(ret+OFFSET)->size      = size;
 
-  return ret;
+  reallocs++;
+  return ret + OFFSET;
 }
 
 void *
 babl_calloc (size_t nmemb,
              size_t size)
 {
-  void *ret = calloc (nmemb, size);
+  void *ret = babl_malloc (nmemb*size);
 
   if (!ret)
     babl_log ("%s(%i, %i): failed", __FUNCTION__, nmemb, size);
 
+  memset (ret, 0, nmemb*size);
+
   callocs++;
+  mallocs--;
   return ret;
 }
 
index 5b8c0e4fe79c85344efb3a01f10e5a44d9c75f01..6465b918449e6c6007f9ad960a31847a57acace9 100644 (file)
@@ -29,6 +29,7 @@ void * babl_realloc         (void         *ptr,
 void * babl_calloc          (size_t        nmemb,
                              size_t        size);
 char * babl_strdup          (const char   *s);
+void * babl_dup             (void         *ptr);
 void   babl_memory_sanity   (void);
 
 #endif